package com.awz.manage.service.impl;

import com.awz.manage.dto.ContractCheckDTO;
import com.awz.manage.dto.ContractInfoDTO;
import com.awz.manage.mapper.ContractMapper;
import com.awz.manage.service.ContractService;
import com.awz.manage.utils.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author lihaoming
 * @create 2022/1/7 14:04
 * @email lyijiazi@qq.com
 * 签约管理业务实现
 **/
@Service
@RequiredArgsConstructor
public class ContractServiceImpl implements ContractService {
    
    private final ContractMapper contractMapper;
    
    /**
     * 查询待处理签约列表
     **/
    @Override
    public AjaxResult getPendingContractList(int pageNum, int pageSize, Integer state, Integer tid, Integer oid, Integer sid, Date sDate, Date eDate, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<ContractInfoDTO> list = contractMapper.selectPendingContractList(state, tid, oid, sid, sDate, eDate, keyword);
        return AjaxResult.success("查询成功", new PageInfo<>(list));
    }
    
    /**
     * 查询已处理签约列表
     **/
    @Override
    public AjaxResult getProcessedContractList(int pageNum, int pageSize, Integer state, Integer tid, Integer oid, Integer sid, Date sDate, Date eDate, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        List<ContractInfoDTO> list = contractMapper.selectProcessedContractList(state, tid, oid, sid, sDate, eDate, keyword);
        return AjaxResult.success("查询成功", new PageInfo<>(list));
    }
    
    @Override
    public AjaxResult modifyContractState(ContractCheckDTO contractCheckDTO) {
        return contractMapper.updateContractState(contractCheckDTO) == 1 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败");
    }
}
